package com.gscitysfy.cus.drain.modules.inspection.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.inspection.entity.DrainInspectionMnJob;
import com.gscitysfy.cus.drain.modules.inspection.entity.DrainInspectionMnPlan;
import com.gscitysfy.cus.drain.modules.inspection.service.IDrainInspectionMnJobService;
import com.gscitysfy.cus.drain.modules.inspection.service.IDrainInspectionMnPlanService;
import com.gscitysfy.cus.drain.modules.inspection.service.IDrainInspectionRlPointService;
import com.gscitysfy.cus.drain.modules.inspection.vo.DrainInspectionMnJobVo;
import com.gscitysfy.cus.drain.modules.inspection.vo.PlanVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2022-10-14 15:00:46
 */
@RestController
@RequestMapping("/inspection/job")
public class DrainInspectionMnJobController {
    @Autowired
    IDrainInspectionMnJobService drainInspectionMnJobService;
    @Autowired
    IDrainInspectionMnPlanService drainInspectionMnPlanService;
    @Autowired
    IDrainInspectionRlPointService drainInspectionRlPointService;
    /**
     * @description: 应用列表
     */
    @Parameters({
            @Parameter(required = false, name = "cmPlanName", description = "计划名称"),
            @Parameter(required = false, name = "cmPlanBasis", description = "计划依据")
    })
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_BASIS, targetField = "cmPlanBasis"),
            @FieldParam(dictType = DicConstant.PLAN_TYPE, targetField = "cmPlanType"),
            @FieldParam(dictType = DicConstant.PLAN_OBJECT_TYPE, targetField = "cmPlanObjectType"),
            @FieldParam(dictType = DicConstant.PLAN_FREQUENCY, targetField = "cmPlanFrequency")
    })
    @PostMapping("/list")
    public Result<Object> list( @RequestBody DrainInspectionMnJobVo drainInspectionMnJob) {
        Page<DrainInspectionMnJob> page = new Page<>();
        if(Objects.isNull(drainInspectionMnJob)){
            drainInspectionMnJob =  new DrainInspectionMnJobVo();
        }
        page.setCurrent(drainInspectionMnJob.getCurrent());
        page.setSize(drainInspectionMnJob.getSize());
        return Result.content(drainInspectionMnJobService.getByPage(page, drainInspectionMnJob));
    }


    /**
     * @description: 任务轨迹
     */
    @GetMapping("/trackList")
    public Result trackList(String id) {

        return Result.content(drainInspectionMnJobService.trackList(id));
    }

    /**
     * @description: 任务问题列表
     */
    @GetMapping("/problemList")
    public Result problemList(String id) {
        return Result.content(drainInspectionMnJobService.problemList(id));
    }


    /**
     * @description: 删除
     */
    @GetMapping("/del")
    public Result del(String ids) {
        if (drainInspectionMnJobService.del(ids)) {
            return Result.content("成功");
        } else {
            return Result.failure("失败");
        }
    }


    /**
     * 导出任务
     *
     * @param response
     * @param drainInspectionMnJob
     */
    @PostMapping("/export")
    @Operation(summary = "导出任务")
    public void export(HttpServletResponse response, @RequestBody DrainInspectionMnJobVo drainInspectionMnJob) throws IOException {
        drainInspectionMnJobService.export(response, drainInspectionMnJob);
    }


    /**
     * 计划待巡检数量
     */
    @GetMapping("/plan-type")
    @Operation(summary = "计划待巡检数量")
    public Result planType() {
      return   Result.content(drainInspectionMnJobService.planType());
    }



    /**
     * 小程序任务列表全部 空 待巡检 1 进行中 2 已完成 3   stutas
     * 小程序任务列表 计划内  1   计划外  2             plan
     * 小程序任务列表 搜索框                           keyWord
     * cmPlanCategory  0 我的巡视     2 我的检查
     */
    @GetMapping("/planXcx")
    @Operation(summary = "小程序任务列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_BASIS, targetField = "cmPlanBasis"),
            @FieldParam(dictType = DicConstant.PLAN_TYPE, targetField = "cmPlanType"),
            @FieldParam(dictType = DicConstant.PLAN_OBJECT_TYPE, targetField = "cmPlanObjectType"),
            @FieldParam(dictType = DicConstant.PLAN_FREQUENCY, targetField = "cmPlanFrequency")
    })
    public Result<Object> planXcx(Page<DrainInspectionMnJob> page,String  stutas,String plan,String keyWord,Integer cmPlanCategory) {
        return   Result.content(drainInspectionMnJobService.planXcx(page,stutas,plan,keyWord,cmPlanCategory));
    }




    /**
     * 详情
     */
    @GetMapping("/detail")
    @Operation(summary = "小程序任务列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_BASIS, targetField = "cmPlanBasis"),
            @FieldParam(dictType = DicConstant.PLAN_TYPE, targetField = "cmPlanType"),
            @FieldParam(dictType = DicConstant.PLAN_OBJECT_TYPE, targetField = "cmPlanObjectType"),
            @FieldParam(dictType = DicConstant.PLAN_FREQUENCY, targetField = "cmPlanFrequency")
    })
    public Result detail(Long  id) {
        return   Result.content(drainInspectionMnJobService.detail(id));
    }


    /**
     * 开始巡查
     */
    @GetMapping("/start")
    @Operation(summary = "开始巡查")
    public Result start(String  id,String jd,String wd) {
        if (drainInspectionMnJobService.start(id,jd,wd)) {
            return Result.content("成功");
        } else {
            return Result.failure("失败");
        }
    }


    /**
     * 暂停巡查
     */
    @GetMapping("/pause")
    @Operation(summary = "暂停巡查")
    public Result pause(String  id) {
        if (drainInspectionMnJobService.pause(id)) {
            return Result.content("成功");
        } else {
            return Result.failure("失败");
        }
    }


    /**
     * 继续存查
     */
    @GetMapping("/continues")
    @Operation(summary = "继续存查")
    public Result continues(String  id) {
        if (drainInspectionMnJobService.continues(id)) {
            return Result.content("成功");
        } else {
            return Result.failure("失败");
        }
    }


    /**
     * 结束巡查
     */
    @GetMapping("/stop")
    @Operation(summary = "结束巡查")
    public Result stop(String  id,String jd,String wd) {
        if (drainInspectionMnJobService.stop(id,jd,wd)) {
            return Result.content("成功");
        } else {
            return Result.failure("失败");
        }
    }


    /**
     * 首页待巡查数量
     */
    @GetMapping("/myJobSize")
    @Operation(summary = "首页待巡查数量")
    public Result myJobSize() {
       return Result.content(drainInspectionMnJobService.myJobSize());
    }



    /**
     * 首页我的统计
     */
    @GetMapping("/myData")
    @Operation(summary = "首页我的统计")
    public Result myData() {
        return Result.content(drainInspectionMnJobService.myData());
    }


    /**
     * 小程序任务列表 待巡检 1 进行中 2 已完成 3
     */
    @GetMapping("/planPc")
    @Operation(summary = "小程序任务列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_BASIS, targetField = "cmPlanBasis"),
            @FieldParam(dictType = DicConstant.PLAN_TYPE, targetField = "cmPlanType"),
            @FieldParam(dictType = DicConstant.PLAN_OBJECT_TYPE, targetField = "cmPlanObjectType"),
            @FieldParam(dictType = DicConstant.PLAN_FREQUENCY, targetField = "cmPlanFrequency")
    })
    public Result<Object> planPc(String  stutas) {
        return   Result.content(drainInspectionMnJobService.planPc(stutas));
    }

    /**
     * pc详情
     */
    @GetMapping("/detailPc")
    @Operation(summary = "pc详情")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_BASIS, targetField = "cmPlanBasis"),
            @FieldParam(dictType = DicConstant.PLAN_TYPE, targetField = "cmPlanType"),
            @FieldParam(dictType = DicConstant.PLAN_OBJECT_TYPE, targetField = "cmPlanObjectType"),
            @FieldParam(dictType = DicConstant.PLAN_FREQUENCY, targetField = "cmPlanFrequency")
    })
    public Result detailPc(Long  id) {
        return   Result.content(drainInspectionMnJobService.detailPc(id));
    }


    /**
     * 概览详情
     */
    @GetMapping("/detailXj")
    @Operation(summary = "pc详情")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_BASIS, targetField = "cmPlanBasis"),
            @FieldParam(dictType = DicConstant.PLAN_TYPE, targetField = "cmPlanType"),
            @FieldParam(dictType = DicConstant.PLAN_OBJECT_TYPE, targetField = "cmPlanObjectType"),
            @FieldParam(dictType = DicConstant.PLAN_FREQUENCY, targetField = "cmPlanFrequency")
    })
    public Result detailXj(Long  id) {
        return   Result.content(drainInspectionMnJobService.detailXj(id));
    }



    /**
     * 概览列表
     */
    @GetMapping("/planXj")
    @Operation(summary = "小程序任务列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_BASIS, targetField = "cmPlanBasis"),
            @FieldParam(dictType = DicConstant.PLAN_TYPE, targetField = "cmPlanType"),
            @FieldParam(dictType = DicConstant.PLAN_OBJECT_TYPE, targetField = "cmPlanObjectType"),
            @FieldParam(dictType = DicConstant.PLAN_FREQUENCY, targetField = "cmPlanFrequency")
    })
    public Result<Object> planXj(String  stutas) {
        return   Result.content(drainInspectionMnJobService.planXj(stutas));
    }

    /**
     * 概览数量
     */
    @GetMapping("/planSl")
    @Operation(summary = "小程序任务列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_BASIS, targetField = "cmPlanBasis"),
            @FieldParam(dictType = DicConstant.PLAN_TYPE, targetField = "cmPlanType"),
            @FieldParam(dictType = DicConstant.PLAN_OBJECT_TYPE, targetField = "cmPlanObjectType"),
            @FieldParam(dictType = DicConstant.PLAN_FREQUENCY, targetField = "cmPlanFrequency")
    })
    public Result<Object> planSl() {
        return   Result.content(drainInspectionMnJobService.planSl());
    }

    /**
     * 进行中所有点位
     */
    @GetMapping("/planJxz")
    @Operation(summary = "小程序任务列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_BASIS, targetField = "cmPlanBasis"),
            @FieldParam(dictType = DicConstant.PLAN_TYPE, targetField = "cmPlanType"),
            @FieldParam(dictType = DicConstant.PLAN_OBJECT_TYPE, targetField = "cmPlanObjectType"),
            @FieldParam(dictType = DicConstant.PLAN_FREQUENCY, targetField = "cmPlanFrequency")
    })
    public Result<Object> planJxz() {
        return   Result.content(drainInspectionMnJobService.planJxz());
    }


}
